<template>
  <div>
    <basic-container>
      <el-breadcrumb separator="/">
        <el-breadcrumb-item>内容管理</el-breadcrumb-item>
        <el-breadcrumb-item>帮助与反馈</el-breadcrumb-item>
        <el-breadcrumb-item>意见反馈</el-breadcrumb-item>
      </el-breadcrumb>
    </basic-container>
    <basic-container>
      <avue-crud
        ref="crud"
        :data="data"
        v-model="form"
        :option="option"
        :page.sync="page"
        @on-load="getList"
        @refresh-change="refreshChange"
        @search-reset="from = {}"
        @search-change="searchChange"
        @row-update="rowUpdate"
        @row-save="rowSave"
        @row-del="rowDel"
      >
        <template slot="last" slot-scope="scope">
          {{ scope.row.modify_time }}
          <el-tag>{{ scope.row.last_operation_info }}</el-tag>
        </template>
      </avue-crud>
    </basic-container>
  </div>
</template>

<script>
import { common } from "@/api/cat/httpRequest";
import { catUrl } from "@/config/env";
import { appUserFeedback as baseURL,uploadFile } from "@/api/cat/baseUrls";
export default {
  data() {
    return {
      page: {
        total: 0,
        pageSize: 10,
        // pageSizes:[1,2,3]
      },
      type: true,
      data: [],
      params: {},
      form: {},
      default: {
        orderByList: "feed_time&DESC",
      },
      option: {
        addBtn: false,
        editBtn: true,
        viewBtn: false,
        delBtn: false,
        searchBtn: true,
        refreshBtn: true,
        excelBtn: false,
        border: true,
        column: [
          {
            label: "反馈时间",
            prop: "feed_time",
            search: true,
            type: "daterange",
            addDisplay: false,
            editDisplay: false,
            addDisabled: true,
            editDisabled: true,
          },
          {
            label: "用户id",
            prop: "user_id",
            type: "input",
            search: true,
            addDisplay: false,
            editDisplay: false,
            addDisabled: true,
            editDisabled: true,
          },
          {
            label: "版本号",
            prop: "app_version",
            type: "input",
            search: true,
            addDisplay: false,
            editDisplay: false,
            addDisabled: true,
            editDisabled: true,
          },
          {
            label: "反馈内容",
            prop: "feedback_content",
            type: "textarea",
            search: true,
            addDisplay: false,
            editDisplay: false,
            addDisabled: true,
            editDisabled: true,
          },
          {
            type: "upload",
            label: "反馈图片",
            limit: 10,
            propsHttp: {},
            dataType: "string",
            prop: "feedback_images",
            listType: "picture-card",
            addDisplay: false,
            editDisplay: false,
            addDisabled: true,
            editDisabled: true,
          },
          {
            label: "邮箱号",
            prop: "email",
            type: "input",
            addDisplay: false,
            editDisplay: false,
            addDisabled: true,
            editDisabled: true,
          },
          {
            label: "机型",
            prop: "phone_type",
            type: "input",
            addDisplay: false,
            editDisplay: false,
            addDisabled: true,
            editDisabled: true,
          },
          {
            label: "上一条反馈(7日内)",
            prop: "pre_feedback_content",
            type: "input",
            addDisplay: false,
            editDisplay: false,
            addDisabled: true,
            editDisabled: true,
          },
          {
            label: "回复内容",
            prop: "reply_content",
            type: "textarea",
          },
          {
            type: "upload",
            label: "回复图片",
            limit: 10,
            propsHttp: {},
            dataType: "string",
            prop: "reply_images",
            listType: "picture-card",
            action: `${catUrl}${uploadFile.uploadFile}`,
            propsHttp: {
              url: "source",
            },
          },
          {
            label: "最后操作信息",
            prop: "last",
            type: "input",
            slot:true,
            addDisplay: false,
            editDisplay: false,
            addDisabled: true,
            editDisabled: true,
          },
        ],
      },
    };
  },
  methods: {
    /**获取列表 */
    async getList() {
      this.loading = true;
      //清空表格列表
      this.data = [];
      //发送请求获取数据
      let response = await common(
        baseURL.pageAndParam,
        {...this.params,...this.default},
        this.page,
        "POST"
      );
      this.page = response.page;
      this.data = response.data;
      this.loading = false;
    },
    /**保存 */
    async rowSave(row, done) {
      delete row["id"];
      row.create_time = new Date();
      let userInfo = this.$store.state.user.userInfo
//       scope.row.admin_id = userInfo.id ? userInfo.id : null
//       scope.row.admin_name = userInfo.username
      row.last_operation_info = userInfo.username;
      row.modify_time = new Date();
      let data = await common(baseURL.save, row, null, "POST");
      if (data.code==null) {
        return;
      }
      this.getList();
      done();
    },
    /**修改 */
    async rowUpdate(row, index, done, loading) {
      let userInfo = this.$store.state.user.userInfo
      row.last_operation_info = userInfo.username;
      row.modify_time = new Date();
      row.state = 0;
      if(row.reply_images.length==0){
        row.reply_images = null;
      }
      let data = await common(baseURL.update, row, null, "POST");
      if (data.code==null) {
        return;
      }
      this.getList();
      done();
    },
    /**刷新 */
    refreshChange() {
      this.getList();
    },
    /**删除 */
    rowDel(row) {
      this.$confirm("此操作将永久删除, 是否继续?", "提示", {
        type: "warning",
      })
        .then(async () => {
          let response = await common(
            baseURL.delete,
            { id: row.feedback_id },
            null,
            "GET"
          );
          // if (response == null) {
          //   return ;
          // }
        })
        .then(() => {
          this.getList();
        });
    },
    /**搜索 */
    searchChange(params, done) {
      params.feedback_content = `${params.feedback_content ? '%'+params.feedback_content+'%' : ""}`;
      params.feed_time = `${params.feed_time ? "!<>!" + params.feed_time : ""}`
      this.params = params;
      this.page.currentPage = 1;
      this.getList();
      if (done) done();
    },
  },
};
</script>